package com.ruoyi.web.controller.combat.useralignment;

import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.ruoyi.combat.util.Topic5Util;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/combat/funcation")
public class CombatAlignFunctionController extends BaseController {

    @Autowired
    private Topic5Util topic5Util;
    @Value("${keti5.forwardUrl}")
    public  String forwardUrl;

    @PostMapping("similarity")
    @Anonymous
    @ApiOperation("用户名称相似度计算算法")
    public AjaxResult Similarity(@RequestBody Map map)
    {
        if(map.get("data1")==null||"".equals(map.get("data1"))){
            return error("参数为空");
        }
        if(map.get("data2")==null||"".equals(map.get("data2"))){
            return error("参数为空");
        }
        String str1 = (String) map.get("data1");
        String str2 = (String) map.get("data2");
        double calculate = topic5Util.calculate(str1, str2);
        return AjaxResult.success(calculate);
    }
    @PostMapping("alignment")
    @Anonymous
    @ApiOperation("对齐算法")
    public AjaxResult alignment(@RequestBody Map data)
    {
        System.out.println(JSONUtil.toJsonStr(data));

        String type = (String) data.get("type");
        if(StringUtils.isEmpty(type)){
            type = "BigAlign";
        }

        String source_dataset = (String) data.get("source_dataset");
        String target_dataset = (String) data.get("target_dataset");
        String groundtruth = (String) data.get("groundtruth");
        String taskId = (String) data.get("taskId");
        topic5Util.GAlign_OK(type, source_dataset,target_dataset,groundtruth,taskId);
        return AjaxResult.success();
    }

    /**
     * 转发
     */
    @PostMapping("forward")
    public AjaxResult getScore(@RequestBody Map data) {
        return AjaxResult.success(HttpUtil.post(forwardUrl,JSONUtil.toJsonStr(data)));
    }



}
